package com.jmye.coding.logback.config;

import com.alibaba.ttl.TransmittableThreadLocal;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: jmye
 * @date: 2025/7/6 16:32
 **/

public class LogContext {
    private static final TransmittableThreadLocal<Map<String, String>> context = new TransmittableThreadLocal<>();

    public static void put(String key, String value) {
        if (context.get() == null){
            context.set(new HashMap<>());
            context.get().put("mainBatchId", "BATCH-001");
        } else {
            context.get().putIfAbsent(key, value);
        }
    }

    public static String get(String key) {
        return context.get().get(key);
    }

    public static void remove(String key) {
        context.get().remove(key);
    }

    public static void clear() {
        context.remove();
    }
}
